home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / prog / pas_all.zip / TI114.ASC < prev    next >
Text File  |  1991-09-11  |  12KB  |  463 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.  
  9.   PRODUCT : TURBO PASCAL                               NUMBER : 114
  10.   VERSION : ALL
  11.        OS : MS-DOS
  12.      DATE : December 4, 1986                             PAGE : 1/7
  13.     TITLE : MS-DOS INTERRUPT 24 TRAP ROUTINE
  14.  
  15.  
  16.  
  17.  
  18.   The following example routines are public domain programs that
  19.   have been uploaded to our Forum on CompuServe. As a courtesy to
  20.   our users that do not have immediate access to CompuServe,
  21.   Technical Support distributes these routines free of charge.
  22.  
  23.   However, because these routines are public domain programs, not
  24.   developed by Borland International, we are unable to provide any
  25.   technical support or assistance using these routines. If you need
  26.   assistance using these routines, or are experiencing
  27.   difficulties, we recommend that you log onto CompuServe and
  28.   request assistance from the Forum members that developed these
  29.   routines.
  30.  
  31.   Thanks to Marshall Brain for the original code for this routine.
  32.  
  33.   These routines provide a method for Turbo Pascal programs to trap
  34.   MS-DOS interrupt 24. INT 24 is called by DOS when a "critical
  35.   error" occurs, and it normally prints the familiar "Abort, Retry,
  36.   Ignore?" message.
  37.  
  38.   With the INT 24 handler installed, errors of this type will be
  39.   passed on to Turbo Pascal as an error. If I/O checking is on,
  40.   this will cause a program crash. If I/O checking is off, IOResult
  41.   will return an error code. The global variable INT24Err will be
  42.   true if an INT 24 error has occurred. The variable INT24ErrorCode
  43.   will contain the INT 24 error code as given by DOS. These errors
  44.   can be found in the DOS Technical Reference Manual. They
  45.   correspond to the error codes returned by the function
  46.   INT24Result, with an offset of 256. INT24Result is used like
  47.   IOResult, and calls IOResult. It then checks INT24Err, and if it
  48.   is true, returns INT24ErrorCode+256, instead.
  49.  
  50.   In most cases, INT24Result should be used, because INT24Err must
  51.   be set back to false, and DOS sometimes restores its normal INT
  52.   24 handler after an error.
  53.   -------------------------------------------------------------------
  54.   **Note: Turbo's normal IOResult codes (and Turbo Access error
  55.   codes) for MS-DOS DO NOT correspond to I/O error numbers given in
  56.   Appendix I of the Turbo Pascal manual, or error codes given in
  57.   the I/O error nn, PC=aaaa/Program aborted message. Here is a
  58.   table of correspondence (all numbers are in hexadecimal and
  59.   (decimal)):
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.  
  75.   PRODUCT : TURBO PASCAL                               NUMBER : 114
  76.   VERSION : ALL
  77.        OS : MS-DOS
  78.      DATE : December 4, 1986                             PAGE : 2/7
  79.     TITLE : MS-DOS INTERRUPT 24 TRAP ROUTINE
  80.  
  81.  
  82.  
  83.  
  84.     IOResult     Turbo error
  85.    ----------    -----------------------------------------------
  86.      00 (0)      00 (0)     none
  87.      01 (1)      90 (144)   record length mismatch
  88.      02 (2)      01 (1)     file does not exist
  89.      03 (3)      F1 (241)   directory is full
  90.      04 (4)      FF (255)   file disappeared
  91.      05 (5)      02 (2)     file not open for input
  92.      06 (6)      03 (3)     file not open for output
  93.      07 (7)      99 (153)   unexpected end of file
  94.      08 (8)      F0 (240)   disk write error
  95.      09 (9)      10 (16)    error in numeric format
  96.      0A (10)     99 (153)   unexpected end of file
  97.      0B (11)     F2 (242)   file size overflow
  98.      0C (12)     99 (153)   unexpected end of file
  99.      0D (13)     F0 (240)   disk write error
  100.      0E (14)     91 (145)   seek beyond end of file
  101.      0F (15)     04 (4)     file not open
  102.      10 (16)     20 (32)    operation not allowed on a logical device
  103.      11 (17)     21 (33)    not allowed in direct mode
  104.      12 (18)     22 (34)    assign to standard files is not allowed
  105.      90 (144)    90 (144)   record length mismatch
  106.  
  107.  
  108.   program CriticalError;
  109.  
  110.   Const INT24Err     : Boolean=False;
  111.         INT24ErrCode : Byte=0;
  112.         OldINT24     : Array [1..2] Of Integer=(0,0);
  113.  
  114.   Var RegisterSet    : Record Case Integer Of
  115.                          1: (AX,BX,CX,DX,BP,SI,DI,DS,ES,Flags: Integer);
  116.                          2: (AL,AH,BL,BH,CL,CH,DL,DH: Byte);
  117.                        End;
  118.  
  119.   Procedure INT24;
  120.     Const FCBFuncs: Array [1..6] Of Byte=(14,15,21,22,27,28);
  121.     Begin
  122.       { To understand this routine, you will need to read the description of
  123.         Interrupt 24h in the DOS manual.  It also helps to examine and trace the
  124.         generated code under DEBUG. }
  125.       Inline($0E/$0E/$1F/$07/$C6/$06/ INT24Err /$01/$89/$EC/$83/$C4/$08/
  126.              $89/$F8/$A2/ INT24ErrCode /$58/$B9/$06/$00/$BF/ FCBFuncs /$F2/
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137.  
  138.  
  139.  
  140.  
  141.   PRODUCT : TURBO PASCAL                               NUMBER : 114
  142.   VERSION : ALL
  143.        OS : MS-DOS
  144.      DATE : December 4, 1986                             PAGE : 3/7
  145.     TITLE : MS-DOS INTERRUPT 24 TRAP ROUTINE
  146.  
  147.  
  148.  
  149.  
  150.              $AE/$75/$04/$B0/$01/$EB/$08/$3C/$39/$B0/$FF/$72/$02/$B0/$83/
  151.              $5B/$59/$5A/$5E/$5F/$89/$E5/$80/$4E/$0A/$01/$5D/$1F/$07/$CF);
  152.   {   Turbo:  PUSH BP                    (Save caller's stack frame
  153.               MOV  BP,SP                   Set up this procedure's stack frame
  154.               PUSH BP                     ?)
  155.       Inline: PUSH CS
  156.               PUSH CS
  157.               POP  DS                    Set DS and ES temporarily to CS
  158.               POP  ES
  159.               MOV  BYTE [INT24Err],1     Set INT24Err to True  (CS:)
  160.               MOV  SP,BP                 Get correct SP;  ADD: Discard saved
  161.               ADD  SP,8                    BP, INT 24h return address & flags
  162.               MOV  AX,DI                 Get INT 24h error code
  163.               MOV  [INT24ErrCode],AL     Save it in INT24ErrCode
  164.               POP  AX                    Get initial DOS call number
  165.               MOV  CX,6                  Search for it in FCBFuncs: is this one
  166.               MOV  DI,Offset FCBFuncs      of the FCB functions that requires an
  167.               REPNZ SCASB                  error code of 01 in AL?
  168.               JNZ  .1
  169.               MOV  AL,1                  Yes: set it
  170.               JMP  .2
  171.  
  172.    .1      CMP  AL,39h                No: is it an FCB function that requires
  173.            MOV  AL,0FFh                 AL=FFh (function <39h)?  Yes: set it.
  174.            JB   .2
  175.            MOV  AL,83h                No: handle call, return error 83h, call
  176.                                         failed via INT 24h.
  177.                                       The error code (1, FFh or 83h) is
  178.                                         returned to the Turbo runtime routine
  179.                                         that called DOS, making it look like
  180.                                         a simple DOS error.  Turbo handles
  181.                                         the I/O error.
  182.    .2      POP  BX                    Pop the rest of the registers saved by
  183.            POP  CX                      the initial INT 21h.
  184.            POP  DX
  185.            POP  SI
  186.            POP  DI
  187.            MOV  BP,SP
  188.            OR   Byte Ptr [BP+0Ah],1   Set the carry flag in the saved Flags reg.
  189.            POP  BP
  190.            POP  DS
  191.            POP  ES
  192.            IRET                       Return to next instruction: all regs.
  193.  
  194.  
  195.  
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202.  
  203.  
  204.  
  205.  
  206.  
  207.   PRODUCT : TURBO PASCAL                               NUMBER : 114
  208.   VERSION : ALL
  209.        OS : MS-DOS
  210.      DATE : December 4, 1986                             PAGE : 4/7
  211.     TITLE : MS-DOS INTERRUPT 24 TRAP ROUTINE
  212.  
  213.  
  214.  
  215.  
  216.                                         restored, AL=error code, carry set. }
  217.   End;
  218.  
  219.  
  220.  
  221.  
  222.   Procedure INT24On;  {Enable INT 24 trapping}
  223.   Begin
  224.     INT24Err:=False;
  225.     With RegisterSet Do
  226.     Begin
  227.       AX:=$3524;
  228.       MsDos(RegisterSet);
  229.       If (OldINT24[1] Or OldINT24[2]) = 0 Then
  230.       Begin
  231.         OldINT24[1]:=ES;
  232.         OldINT24[2]:=BX;
  233.       End;
  234.       DS:=CSeg;
  235.       DX:=Ofs(INT24);
  236.       AX:=$2524;
  237.       MsDos(RegisterSet);
  238.     End;
  239.   End;
  240.  
  241.   Procedure INT24Off;  {Disable INT 24 trapping.  Should be done at the
  242.                         end of the program, if you plan to be running
  243.                         the program from within the Turbo compiler.}
  244.   Begin
  245.     INT24Err:=False;
  246.     If OldINT24[1]<>0 Then
  247.       With RegisterSet Do
  248.       Begin
  249.         DS:=OldINT24[1];
  250.         DX:=OldINT24[2];
  251.         AX:=$2524;
  252.         MsDos(RegisterSet);
  253.       End;
  254.     OldINT24[1]:=0;
  255.     OldINT24[2]:=0;
  256.   End;
  257.  
  258.   Function INT24Result: Integer;
  259.  
  260.  
  261.  
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268.  
  269.  
  270.  
  271.  
  272.  
  273.   PRODUCT : TURBO PASCAL                               NUMBER : 114
  274.   VERSION : ALL
  275.        OS : MS-DOS
  276.      DATE : December 4, 1986                             PAGE : 5/7
  277.     TITLE : MS-DOS INTERRUPT 24 TRAP ROUTINE
  278.  
  279.  
  280.  
  281.  
  282.   Var I : Integer;
  283.  
  284.   Begin
  285.     I:=IOResult;
  286.     If INT24Err Then
  287.  
  288.     Begin
  289.       I:=I+256*(INT24ErrCode+1);
  290.       INT24On;
  291.     End;
  292.  
  293.  
  294.     INT24Result:=I;
  295.   End;
  296.  
  297.  
  298.   {  INT24Result returns all the regular Turbo IOResult codes if no
  299.      critical  error has occurred.   If a critical error,  then the
  300.      following  values are added to the error code from Turbo (each
  301.      is 256 times the INT24ErrorCode value returned by DOS):
  302.  
  303.       256:  Attempt to write on write protected disk
  304.       512:  Unknown unit                  [internal dos error]
  305.       768:  Drive not ready               [drive door open or bad drive]
  306.      1024:  Unknown command               [internal dos error]
  307.      1280:  Data error (CRC)              [bad sector or drive]
  308.      1536:  Bad request structure length  [internal dos error]
  309.      1792:  Seek error                    [bad disk or drive]
  310.      2048:  Unknown media type            [bad disk or drive]
  311.      2304:  Sector not found              [bad disk or drive]
  312.      2560:  Printer out of paper          [anything that the printer
  313.                                            might signal]
  314.      2816:  Write fault                   [character device not ready]
  315.      3072   Read fault                    [character device not ready]
  316.      3328:  General failure               [several meanings]
  317.     If you need the IOResult part, use
  318.       I:=INT24Result and 255; [masks out the INT 24 code]
  319.     For the INT 24 code, use
  320.       I:=INT24Result Shr8;    [same as Div 256, except faster]
  321.     INT24Result clears both error codes, so you must assign it  to
  322.     a variable if you want to extract both codes:
  323.       J:=INT24Result;
  324.       Writeln('Turbo IOResult  = ',J And 255);
  325.  
  326.  
  327.  
  328.  
  329.  
  330.  
  331.  
  332.  
  333.  
  334.  
  335.  
  336.  
  337.  
  338.  
  339.   PRODUCT : TURBO PASCAL                               NUMBER : 114
  340.   VERSION : ALL
  341.        OS : MS-DOS
  342.      DATE : December 4, 1986                             PAGE : 6/7
  343.     TITLE : MS-DOS INTERRUPT 24 TRAP ROUTINE
  344.  
  345.  
  346.  
  347.  
  348.       Writeln('DOS INT 24 code = ',J Shr 8); }
  349.  
  350.  
  351.   { Main program }
  352.   { Run this with printer off (or no printer), and nothing in drive A }
  353.  
  354.   Var F : File;
  355.       I : Integer;
  356.  
  357.   Procedure PrinterTest;
  358.   Begin
  359.     WriteLn(LST,'test');
  360.  
  361.     I:=INT24Result;
  362.     If I<>0 Then
  363.       WriteLn('Printer error: ',I)
  364.     Else
  365.       WriteLn('Printer OK');
  366.   End;
  367.  
  368.   Procedure FileTest;
  369.   Begin
  370.     Assign(F,'A:FILE');
  371.     {$I-}
  372.     Reset(F);
  373.     {$I+}
  374.     I:=INT24Result;
  375.     If I<>0 Then
  376.       WriteLn('Open failure on A:FILE :  INT24Result=',I)
  377.     Else
  378.     begin
  379.       WriteLn('A:FILE exists');
  380.       Close(F);
  381.     end;
  382.   End;
  383.  
  384.   Begin
  385.     INT24On;
  386.     PrinterTest;
  387.     FileTest;
  388.     PrinterTest;
  389.     INT24Off;
  390.     FileTest;
  391.  
  392.  
  393.  
  394.  
  395.  
  396.  
  397.  
  398.  
  399.  
  400.  
  401.  
  402.  
  403.  
  404.  
  405.   PRODUCT : TURBO PASCAL                               NUMBER : 114
  406.   VERSION : ALL
  407.        OS : MS-DOS
  408.      DATE : December 4, 1986                             PAGE : 7/7
  409.     TITLE : MS-DOS INTERRUPT 24 TRAP ROUTINE
  410.  
  411.  
  412.  
  413.  
  414.     PrinterTest;
  415.   End.
  416.  
  417.  
  418.  
  419.  
  420.  
  421.  
  422.  
  423.  
  424.  
  425.  
  426.  
  427.  
  428.  
  429.  
  430.  
  431.  
  432.  
  433.  
  434.  
  435.  
  436.  
  437.  
  438.  
  439.  
  440.  
  441.  
  442.  
  443.  
  444.  
  445.  
  446.  
  447.  
  448.  
  449.  
  450.  
  451.  
  452.  
  453.  
  454.  
  455.  
  456.  
  457.  
  458.  
  459.  
  460.  
  461.  
  462.  
  463.